class Solution {
    public:
        int longestArithSeqLength(vector<int>& nums) {
            int n = nums.size();
            vector<vector<int>> dp(n,vector<int>(n,2));
            unordered_map<int,int> hash;
            int ret = 2;
            hash[nums[0]] = 0;
            for(int i = 1 ; i < n ; i++){
                for( int j = i+1; j < n; j++){
                    if(hash.count(2*nums[i]-nums[j])){
                        dp[i][j] = dp[hash[ 2*nums[i]-nums[j] ]][i] + 1;
                        ret = max(ret,dp[i][j]);
                    }
                }
                hash[nums[i]] = i;
            }
            return ret;
        }
    };